class Solution:
    def minOperations(self, boxes: str) -> list:
        front = [[0, 0] for _ in range(len(boxes))]
        back = [[0, 0] for _ in range(len(boxes))]
        for i in range(len(boxes)):
            if boxes[i] == '1':
                front[i][0] += 1
            if i > 0:
                front[i][0] += front[i - 1][0]
                front[i][1] += front[i - 1][1]
                front[i][1] += front[i - 1][0]
        for i in range(len(boxes) - 1, -1, -1):
            if boxes[i] == '1':
                back[i][0] += 1
            if i < len(boxes) - 1:
                back[i][0] += back[i + 1][0]
                back[i][1] += back[i + 1][1]
                back[i][1] += back[i + 1][0]
        ans = [0 for _ in range(len(boxes))]
        for i in range(len(boxes)):
            ans[i] = front[i][1] + back[i][1]

        return ans
